import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import {parseTime} from './utils/time'
import "./registerServiceWorker";
import axios from "axios"
import tabbar from "./components/tabbar.vue"
import Vant from 'vant';
import 'vant/lib/index.css';
import qs from 'qs'
import Vconsole from 'vconsole'

// const vConsole = new Vconsole()
Vue.prototype.$tw = parseTime
axios.defaults.baseURL = 'http://sza.hzlyzhenzhi.com/api/'
axios.interceptors.request.use(function(config){
  const token=localStorage.getItem('token')
  const uid=localStorage.getItem('uid')
//判断请求的类型
//如果是post请求就把默认参数拼到data里面
//如果是get请求就拼到params里面
  if(config.method==='post'){
    let data = qs.parse(config.data)
    config.params={
      api_token:token,
      uid:uid,
      ...config.params
    }
  }else if(config.method==='get'){
    config.params={
      api_token:token,
      uid:uid,
      ...config.params
    }
  }
  return config;
},function(error){
  return Promise.reject(error);
})
Vue.use(Vant);
Vue.component('tabbar', tabbar);
Vue.prototype.$axios = axios
Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
